package com.defysoft.waukidsbus.main;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.defysoft.waukidsbus.BaseActivity;
import com.defysoft.waukidsbus.R;
import com.defysoft.waukidsbus.end.End_Select;
import com.defysoft.waukidsbus.start.Start_Select;

public class Main_main extends BaseActivity implements OnClickListener {
	Toolbar toolbar;
	ImageView start;
	ImageView end;
	TextView logout;
	private SharedPreferences login_code;
	private SharedPreferences.Editor editor;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main_main);
		setStartData();
	}

	@Override
	public void setStartData() {
		// TODO Auto-generated method stub
		super.setStartData();
		login_code = getSharedPreferences("login_code", MODE_PRIVATE);
		editor=login_code.edit();
		toolbar = (Toolbar) findViewById(R.id.MAIN_TOOL);

		toolbar.setNavigationOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		logout=(TextView)findViewById(R.id.MAIN_LOGOUT);
		logout.setOnClickListener(this);
		start = (ImageView) findViewById(R.id.MAIN_START);
		end = (ImageView) findViewById(R.id.MAIN_END);
		start.setOnClickListener(this);
		end.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.MAIN_START:
			startActivity(new Intent(this, Start_Select.class));
			break;
		case R.id.MAIN_END:
			startActivity(new Intent(this, End_Select.class));
			break;
		case R.id.MAIN_LOGOUT:
			AlertDialog.Builder builder = new AlertDialog.Builder(
					Main_main.this);
			builder.setMessage(
					"로그아웃 하겠습니까?")
					.setCancelable(false)
					.setPositiveButton("네",
							new DialogInterface.OnClickListener() {
								@Override
								public void onClick(DialogInterface dialog,
										int which) {
									editor.putString("sch_code", null);
									editor.putString("sch_name", null);
									editor.commit();
									startActivity(new Intent(Main_main.this, Main_Intro.class));
									dialog.cancel();
									finish();
								}
							})
					.setNegativeButton("아니오",
							new DialogInterface.OnClickListener() {
								@Override
								public void onClick(DialogInterface dialog,
										int which) {
									dialog.cancel();
								}
							});
			AlertDialog alert = builder.create();
			alert.show();
			break;
		}
	}
}
